from django import http


def del_cookies_middleware(get_response):  #
    """
    print('********')
    print('初始化中间件:处理删除cookie操作')
    print('中间件位置:carts.middleware.del_cookies_middleware')
    print('使用方法:在request中增加一个 del_cookies的列表'
          ', 列表中的key会被从cookies中删除')
    print('********')
    """

    def middleware(request):
        response = get_response(request)
        for key in getattr(request, 'del_cookies', []):
            response.delete_cookie(key)

        return response

    return middleware
